[#ftl]
[#compress]
[#if applicationMode = "PROD"](function(){[/#if]

[@shrinksafe key="index1" cached=shrinkCached shrink=shrink CompilationLevel="WHITESPACE_ONLY"]

	//dynamic load external css 
	_loadCss("/dojo10/dojo/resources/dnd.css");
	_loadCss("/dojo10/dojox/layout/resources/ResizeHandle.css");
	_loadCss("/dojo10/dojox/grid/resources/claroGrid.css");
	[#if applicationMode = "PROD"]
	_loadCss("/${project}/index.css");
	[/#if]
//		if(window.addEventListener){
//			window.addEventListener("online", function(){
//				console.log("***************online");
//			}, false);
//			window.addEventListener("offline",function(){
//				console.log("***************offline");
//			}, false);
//		}	
		require({async:false},["dojo/store/Memory","dojo/_base/connect","dojo/_base/event","dijit/registry","dojo/string","dojo/mouse","dojo/request","dojo/topic","dojo/parser","dojo/_base/window","dojo/dom-style","dojo/dom","dojo/has", "dojo/sniff","dojo/_base/lang","dojo/_base/kernel"
		                       ,"dojo/dom-geometry","dojo/dom-construct","dojo/dom-class","dojo/dom-attr","dojo/on","dojo/keys","dojo/query","dojo/_base/array","dojo/aspect","dojo/date/locale","dojo/json"
		                       ,"dojo/_base/declare","dijit/_WidgetBase","dijit/_TemplatedMixin","dijit/_WidgetsInTemplateMixin"
		                       ,"dijit/layout/AccordionContainer","dijit/layout/BorderContainer","dijit/layout/TabContainer","dijit/layout/ContentPane"
		                       ,"dijit/MenuBar","dijit/MenuBarItem","dijit/PopupMenuBarItem","dijit/Toolbar","dijit/form/Button"
		                       ,"dijit/_Contained","dijit/InlineEditBox","dojo/i18n"	                       	                       
		                       ]
		,function(Memory,connect,_event,registry,string,mouse,request,topic,parser,_window,style,dom,has,sniff,lang
				,kernel,geometry,construct,domClass,attr,on,keys,query,array,aspect,locale,json
				,declare,_WidgetBase,_TemplatedMixin,_WidgetsInTemplateMixin,AccordionContainer,BorderContainer,TabContainer
				,ContentPane,MenuBar,MenuBarItem,PopupMenuBarItem,Toolbar,Button,_Contained
				,InlineEditBox,i18n){
			 var str = arguments.callee.toString().replace(/\n*/g,"").replace(/\s*/g,"");
			 var args = str.substring(str.indexOf("(") + 1,str.indexOf(")")).split(",");
			 //console.log("*****",args);
			 for(var i = args.length - 1; i >= 0; i--){
				 window[args[i]] = arguments[i];
			 }
			 
			 console.log("######browser firefox=",has("ff"),"ie=",has("ie"),"opera=",has("opera"),"chrome=",has("chrome"));			 
		});
		
		require({async:false},["dojo/NodeList-dom","dojo/NodeList-html","dojo/NodeList-data"],function(){});
[/@]			
[@shrinksafe key="index2" cached=shrinkCached shrink=shrink]		
		window["ls"] = window["localStorage"];	
		if(!window["ls"]){
			window["ls"] = {};
		}
		
		[@messageUtility/]
		[@showWarningMessage/] 
	   var handle = topic.subscribe("agile.ready", function(obj){
			if(obj == "Application"){
				style.set(dom.byId("welcomeNode"),{display:"none"});
				handle.remove();
			}		
		});
		
		var cache = window.applicationCache;
		if(cache){
		  cache.addEventListener('updateready', function(e) {
			  cache.swapCache();				
			  	window.location.reload();	
		  }, false);
		}
		showLoadingMessage("Step1/3 Loading Application");
[#--
//		[#if applicationMode="PROD"]				
//		var versionUri = "${webAppHost}${context}/${project}/version.js";
//		[#else]
//		var versionUri = "${webAppHost}${context}/${project}/require?widget=version";
//		[/#if]		
//		var requireDownload = true;
//		if(window["ls"] && window["ls"]["bootstrap"]){
//			console.log("check version:",versionUri);
//			console.log("local version:",window["ls"]["version"]);
//			  request.get(versionUri, {
//				  handleAs:"text",sync:true ,preventCache:false
//			  }).then(function(data){
//					console.log("server version:",data);
//					window["ls"]["version"] = data;	
//			  }, function(err){
//				  console.error("failed to check version",err);		
//			  });			
//		}	
--]
	  [#if applicationMode = "DEV"]	
	  	[#include "bootstrap.ftl"/]
	  [#else]
	  	
      window.setTimeout(function(){		    	
		var __loadStartTime = new Date().getTime();				
		console.info("*****Beyond Prototype loading starts at ",new Date());
		[#if applicationMode="PROD"]				
		var bootstrapUri = "${webAppHost}${context}/${project}/bootstrap.js";
		[#else]
		var bootstrapUri = "${webAppHost}${context}/${project}/require?widget=bootstrap";
		[/#if]
						 
		  request.get(bootstrapUri, {
			  handleAs:"text"
			  ,sync:false 
			  ,preventCache:false
		  }).then(
		     function(resp){
				//window.clearInterval(progressHandler);
//						showLoadingMessage("Step1/3 Loading Application 100%");
				window.setTimeout(function(){
					var __loadCompleteTime = new Date().getTime();
					console.info("*****Beyond Prototype loading completes at ",new Date()," load toal time(ms) used=",__loadCompleteTime - __loadStartTime);
//							showLoadingMessage("Step2/3 Initializing Application");	
					window.setTimeout(function(){
						try{							
							eval(resp);
						}catch(e){
							//topic.publish("agile.message","error",null,"Error occurred while initializing application",e);
							console.error("Error occurred while initializing application[index]",e);
							showErrorMessage("Error occurred while initializing application");
						}
					},500);
				},500);
			}
		    ,function(err){	
		    	//window.clearInterval(progressHandler);
				//topic.publish("agile.message","error",null,err.message+".Error occurred while loading application",err);
		    	showErrorMessage(err.message+".Error occurred while loading application");
			}
		  );				
		},50);	
	  [/#if]	
[/@]

[#if applicationMode = "PROD"]})();[/#if]
[/#compress]